package com.program.cloudmanagesystem.complaint.controller;
import com.program.cloudmanagesystem.complaint.domain.*;
import com.program.cloudmanagesystem.complaint.persistence.GuideFeign;
import com.program.cloudmanagesystem.complaint.persistence.ScenicSpotFeign;
import com.program.cloudmanagesystem.complaint.persistence.TripTeamFeign;
import com.program.cloudmanagesystem.complaint.service.ComplaintService;
import com.program.cloudmanagesystem.complaint.persistence.HotelFeign;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//import javax.jws.WebParam;
//import javax.jws.soap.SOAPBinding;
import java.util.List;

@RestController
@RequestMapping("/")
public class ComplaintController {
    @Autowired
    private ComplaintService complaintService;

    @Autowired
    private HotelFeign hotelFeign;

    @Autowired
    private TripTeamFeign tripTeamFeign;

     @Autowired
    private GuideFeign guideFeign;

      @Autowired
    private ScenicSpotFeign scenicSpotFeign;

    @GetMapping("/Complaint")
    public List<Complaint> showComplaints() {
        return complaintService.showComplaints();
    }

    @PostMapping ("/searchComplaint")
    public Complaint searchComplaint(@RequestBody Complaint complaint){
        return complaintService.searchComplaint(complaint.getObject());
    }

    @PostMapping("/insertComplaint")
    public String insertComplaint(@RequestBody Complaint complaint) {
        complaintService.insertComplaint(complaint);
        return "OK";
    }

    @PostMapping("/updateScore")
    public String updateData(@RequestBody Complaint complaint) {
        complaintService.insertComplaint(complaint);
        if(complaint.getState().equals("01")){
            ScenicSpot scenicSpot=new ScenicSpot();
            scenicSpot.setId(Integer.parseInt(complaint.getObject()));
            scenicSpot.setScore(complaint.getScore());
            scenicSpotFeign.send(scenicSpot);
            return "done01";
        }
        else if (complaint.getState().equals("02")) {
            Hotel hotel = new Hotel();
            hotel.setScore(complaint.getScore());
            hotel.setId(complaint.getObject());
            hotelFeign.send(hotel);
            return "done02";
        }
        else if(complaint.getState().equals("03")){
            TripTeam tripTeam = new TripTeam();
            tripTeam.setCredit(complaint.getScore());
            tripTeam.setTeamid(complaint.getObject());
            tripTeamFeign.send(tripTeam);
            return "done03";
        }
        else if(complaint.getState().equals("04")){
            Guide guide = new Guide();
            guide.setScore(complaint.getScore());
            guide.setId(Integer.parseInt(complaint.getObject()));
            guideFeign.send(guide);
            return "done04";
        }
        else
            return "dont";
    }
}
